<?php

/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
App::uses('AppModel', 'Model');

/**
 * Setting Model
 *
 */
class Setting extends AppModel
{

    public $name = 'Setting';

    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array(
        'System-language' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Please select the system language.'
            )
        ),
        'System-timezone' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Please select the system timezone.'
            )
        ),
    );

    public function __construct($id = false, $table = null, $ds = null)
    {
        App::uses('CakeTime', 'Utility');

        $this->validate['System-language']['isinlist'] = array(
            'rule' => array('inList', array_keys(AppLanguages::getAll())),
            'message' => 'Please select a valid language.'
        );

        $this->validate['System-timezone']['isinlist'] = array(
            'rule' => array('inList', array_keys(CakeTime::listTimezones(null, null, false))),
            'message' => 'Please select a valid timezone.'
        );

        parent::__construct($id, $table, $ds);
    }

    public function afterSave($created)
    {
        parent::afterSave($created);
        Cache::delete('AppConfigurationCache');
    }

}
